package cn.TcpService;

public class CoilService implements Runnable {
	private CoilSchedule coilSchedules[];

	public CoilService(CoilSchedule coilschedules[]) {
		this.coilSchedules = coilschedules;
	}

	public void StartService() {
		// 将自己的run方法启动
		Thread thisThread = new Thread(this);
		thisThread.start();
	}

	public void run() {
		long timeStamp = 0;
		System.err.println("==========CoilService.java启动计划任务Task==========");
		for (int i = 0; i < coilSchedules.length; i++) {
			CoilTask ct = new CoilTask(coilSchedules[i]);
			try {
				Thread.sleep(coilSchedules[i].getDelay());
			} catch (Exception e) {
				e.printStackTrace();
			}
			if (i > 1) {
				ct.startSwitchTask(coilSchedules[i - 1]);
			} else {
				ct.startSwitchTask(null);
			}
			//设置延迟  执行时间。
			try {
				Thread.sleep(coilSchedules[i].getDelay());
			} catch (Exception e) {
				e.printStackTrace();
			}
            //关闭开关。
			
		}

		System.err.println("==========CoilService.java计划任务结束Task==========");
	}
}
